package com.chandon.T02_functional;

import com.chandon.common.Cv;

import java.util.function.Supplier;

/**
 * * jdk1.8中提供的函数式接口与输入输出的要求
 * *
 * *      Supplier:1个输出
 * *          Supplier<T>
 * * ------------------------------
 * *      Consumer:1个输入
 * *          Consumer<T>
 * *      BiConsumer:2个输入
 * *          BiConsumer<T,U>
 * * ------------------------------
 * *      Function:1个输入1个输出，类型不同
 * *          Function<T, R>
 * *
 * *      BiFunction:2个输入,1个输出，类型不同
 * *          BiFunction<T, U, R>
 * * ------------------------------
 * *      UnaryOperator:1个输入1个输出，类型相同
 * *          UnaryOperator<T> extends Function<T, T>
 * *
 * *      BinaryOperator:2个输入1个输出，类型相同
 * *         BinaryOperator<T> extends BiFunction<T,T,T>
 *
 * @author Dong
 * @version 1.0
 * @date 2021-04-14 1:57
 */

public class T00_TestSupplier {
    public static void main(String[] args) {

        /*
            Supplier用法
         */
        Cv cv0 = new Cv();
        Cv cv1 = new Cv();
        System.out.println(cv0 == cv1);
        System.out.println(cv0.hashCode() == cv1.hashCode());
        System.out.println(cv0);
        System.out.println(cv1);
        System.out.println("---------------------------1");

        Supplier<Cv> cvSupplier0 = Cv::new;
        Cv cv2 = cvSupplier0.get();
        Cv cv3 = cvSupplier0.get();
        System.out.println(cv2 == cv3);
        System.out.println(cv2.hashCode() == cv3.hashCode());
        System.out.println(cv2);
        System.out.println(cv3);
        System.out.println("---------------------------2");



        Supplier<Cv> cvSupplier3 = () -> {
            return new Cv("asami", 18, 10);
        };
        System.out.println(cvSupplier3.get() == cvSupplier3.get());

        System.out.println("---------------------------3");


        Supplier<Cv> cvSupplier4 = () -> new Cv("asamiyui", 17, 10);
        Cv cv4 = cvSupplier4.get();
        Cv cv5 = cvSupplier4.get();
        System.out.println(cv4 == cv5);
        System.out.println(cv4.hashCode() == cv5.hashCode());
        System.out.println(cv4);
        System.out.println(cv5);
        System.out.println("---------------------------4");

    }
}
